<!DOCTYPE HTML>
<html>
<?php
	include_once 'meta.php';
?>
<?php
	include_once 'header.php';
	include_once '../pages/config.php';
	
	$page=$_SERVER['REQUEST_URI'];
	$segments=explode('id=',trim($page,'id='));
	
	if (sizeof($segments) !== 2)
		header("Location: index.php");
	else
	{				
		$tail = $segments[1];
		$number = intval ($tail);
		//echo $tail;
	}
	
	//connect to database
	$connection = mysql_connect ($host, $username, $password) or die ( json_encode ( array (
		'success' => false,
		'errors' => $connect_error . mysql_error () 
		) ) );
	mysql_select_db ( $db, $connection ) or die ( json_encode ( array (
		'success' => false,
		'errors' => $connect_error. mysql_error () 
		) ) );
	$result = @mysql_query ( "select * from auction_view where auctionID = " . $tail);
		if (! $result) {
			die ( 'errors' );
		}
	$result = mysql_fetch_assoc ( $result );
	
	$bidder = @mysql_query ( "select * from bid where auctionID = " . $tail);
	if (!$bidder){
		die('errors');	
	}
	$productName = $result['productID'];
	$productDescription = @mysql_query ( "select description from product where productID = " . $productName);
	if ($result['image'] == NULL) $image = "1000thoc.jpg"; else $image = $result['image'];
	$realPrice = $result['price'];
	$price = $result['auction_price'];
?>
<div id="divMain" class="main-tung">
	<div class="content-sp">
    	<div class="title-sp">
			<span id=""><?php echo $productName;?></span>
        </div>
        <div id="divmainphoto">
            <div id="gallery">
                 <div id="slides">
                    <div class="slide">
                        <img id="" alt="side" src="../uploads/ProductUpload/<?php echo $image;?>" style="height:250px;" />
                    </div>
                 </div>
            </div>
        </div>
        <div id="divAuctionLittle">
			<div class="tt-bid" ref='bid-214'>
				<div class="tit-bid">
					<span id=""><?php echo $productName;?></span>
                </div>
                <div class="content-bid">
                    <img id="" class="img-home" src="../uploads/ProductUpload/<?php echo $image;?>" />
                    <p class="giatt">Giá thị trường:
                         <span id=""><?php echo $realPrice;?> đ</span></p>
                    <p style="line-height: 3px;"></p>
                    <div id='divTimeLeft' class="dongho" ref='66573779.0955'></div>
                    <p class="gia"><span id=""><?php echo $price; ?></span></p>
                    <p class="caonhat">Người trả cao nhất</p>
                    <p class="nguoidau"><span id="">gamedota92</span></p>
                    <div style="margin-left: 45px;">
						<a id="" class="btBid1" onclick="sendBidCmd(222)" href="javascript:void(0)">BID</a>
					</div>
                </div>
                <div class="footer-sp">
                	<span id="" class="buocgia">50đ</span>
                    <div class="dtien">
						<div class="img-tien">
							<img id="ContentPlaceHolder_ctl00_AuctionLittle1_imgCoinType" src="../images/img-coin2.png" />
                        </div>
                        <div class="tien"><span id="ContentPlaceHolder_ctl00_AuctionLittle1_lblPriceStepBID">x50</span></div>
					</div>
                </div>
            </div>
            <div id='divTopUser_222'>
				<div class="topbid">
					<table class="tbtop">
						<tr class="headtb">
			                <td>
                    			Người chơi
                			</td>
                			<td>
                    			Giá
                			</td>
            			</tr>
                        <?php
							$count = 0;
							while ( $each = mysql_fetch_assoc ( $bidder ) ){
							$count++;
							if ($count == 10) break;
						?>
  						<?php
						if ($count%2 == 1){ ?>
                        <tr class ='le-sp'>
                        	<td>
                            	<span id=""><?php echo $each['username'];?></span>
							</td>
                        	<td>
                            	<span id=""><?php echo $each['Bid_price'];?></span>
                        	</td>
                    	</tr>
                        <?php }else{ ?>
                    	<tr class ='chan-sp'>
                        	<td>
                            	<span id=""><?php echo $each['username'];?></span>
                        	</td>
                        	<td>
                            	<span id=""><?php echo $each['Bid_price'];?></span>
                        	</td>
                    	</tr>
                        <?php
						}}
						?>
					</table>
				</div>
			</div>
            <div class="autobid">
            
            </div>
            <div class="phantich">
				<div class="ttl">
					<p>Phân tích đấu giá</p>
            		<p>&nbsp;</p>
				</div>
                <div class="wrappt">
					<div class="left-pt">
						<div class="gd">Giá đấu:
							<label><?php echo $price;?></label>
						</div>
						<div class="pvc">Phí vận chuyển:
							<label>--</label>
						</div>
						<div class="cp">Chi phí mua hàng:
							<label><?php echo $price;?></label>
						</div>
					</div>
					<div class="right-pt">
						<div class="gtt">Giá thị trường:
							<label><?php echo $realPrice;?></label>
					</div>
					<div class="cp2">Tiết kiệm: <b class="tk"><?php echo ($realPrice - $price);?></b></div>
				</div>
			</div>
        </div>
        <div class="ttsp">
			<div class="bordertop-sp"></div>
            <div class="titlesp">THÔNG TIN CHI TIẾT SẢN PHẨM</div>
            <div class="text-sp"><?php echo $productDescription;?>
                <div style="clear: both">
                </div>
			</div>
			<div style="clear: both"></div>
		</div>
    </div>
</div>
<?php			
	include_once 'footer.php';
?>
</html>